package com.isoft.demo01.dao.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.isoft.demo01.dao.GameManageDao;
import com.isoft.demo01.entity.Game;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class GameManageRepository {
    @Autowired
    GameManageDao gameManageDao;

    public int insert(Game game) {
        return gameManageDao.insert(game);
    }

    public int updateById(Game game) {
        return gameManageDao.updateById(game);
    }

    public int deleteById(Integer gameid) {
        return gameManageDao.deleteById(gameid);
    }

    public int deleteByIds(List<Integer> gameids) {
        return gameManageDao.deleteBatchIds(gameids);
    }

    public Game getDetailById(Integer gameid) {
        return gameManageDao.getDetailById(gameid);
    }

    /**
     * 只查询游戏的photo字段
     *
     * @param gameid
     * @return
     */
    public Game getPhotoById(Integer gameid) {
        QueryWrapper<Game> wrapper = new QueryWrapper<>();
        wrapper.select("photo");
        wrapper.eq("gameid", gameid);
        Game g = gameManageDao.selectOne(wrapper);
        return g;
    }

    public List<Game> getPhotoByIds(List<Integer> gameids) {
        QueryWrapper<Game> wrapper = new QueryWrapper<>();
        wrapper.select("photo");
        wrapper.in("gameid", gameids);
        return gameManageDao.selectList(wrapper);
    }

    public Page<Game> page(Integer currentPage, Integer size, String gamename, Integer typeid, String introduce) {
        Page<Game> page = new Page<>();
        page.setCurrent(currentPage);
        page.setSize(size);
        QueryWrapper<Game> wrapper = new QueryWrapper<>();
        if (null != typeid) {
            wrapper.eq("typeid", typeid);
        }
        if (null != gamename) {
            wrapper.like("gamename", gamename);
        }
        if (null!=introduce){
            wrapper.like("introduce",introduce);
        }
        return gameManageDao.selectPage(page,wrapper);

    }


}
